<template>
  <div class="payment">
    <div class="content">
      <div class="step-box">
        <div class="left">
          <span class="img"></span>
          <span class="text">订单支付</span>
        </div>
        <div class="steps">
          <div class="item">
            <div class="number">step 01.</div>
            <div class="text">选择购买商品</div>
          </div>
          <div class="item">
            <div class="number">step 02.</div>
            <div class="text">确认订单信息</div>
          </div>
          <div class="item active">
            <div class="number">step 03.</div>
            <div class="text">支付完成订单</div>
          </div>
        </div>
      </div>
      <div class="payment-con">
        <div class="pay-box">
          <div class="pay-info">
            <div class="tag success"></div>
            <div class="item">
              <div class="tit">订单提交成功，请尽快付款！</div>
              <div class="total-pay">
                应付总额：<span class="price"><span>{{order.totalPrice.toFixed(2)}}</span></span>
              </div>
            </div>
            <div class="item">
              <div class="time" v-if="true">
                请在<span class="warning">30:00</span>内付款，否则交易会被取消
              </div>
              <div class="reset-time" v-else>订单已过期，请重新下单</div>
            </div>
          </div>
        </div>
        <div class="section-payment">
          <div class="tit">选择支付方式</div>
          <div class="con">
            <div class="item">
              <img src="./images/R-C.png" alt="" />
            </div>
          </div>
        </div>
        <div class="section-payment">
          <a href="javascript:;" class="btn" @click="handlePay">立即付款</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="pay">
import useTradeStore from '@/stores/modules/trade';
import useUserStore from '@/stores/modules/user';
import { payOrder } from '@/api/order';
import { useRouter, useRoute } from "vue-router";
import {ElMessage} from "element-plus"

//获取路由器对象
let $router = useRouter();
let $route = useRoute();

let userId = useUserStore().user._id
let order = useTradeStore().order

const handlePay =async () => {
  let orderNumber = order.orderNumber
  let result = await payOrder({userId,orderNumber})
  if(result.code == 200){
    $router.push('/paySuccess')
  }else{
    ElMessage.error(result.msg)
  }
}
</script>

<style lang="scss" scoped>
.payment {
  min-height: 535px;
  padding-bottom: 40px;
  background-color: #f9f9f9;
  .content {
    width: 1200px;
    margin: auto;
    .step-box {
      display: flex;
      height: 70px;
      padding: 0 20px 7px;
      box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.05);
      margin-bottom: 30px;
      border-bottom: 2px solid #4caf50;
      .left {
        flex: 1;
        margin-top: 16px;
        .img {
          background: url(../../assets/icons.d354c61.png) no-repeat -86px -249px;
          display: inline-block;
          vertical-align: top;
          height: 38px;
          width: 38px;
        }
        .text {
          display: inline-block;
          vertical-align: top;
          height: 38px;
          line-height: 38px;
          font-size: 15px;
          font-weight: 600;
        }
      }
      .steps {
        display: flex;
        .item {
          padding-left: 90px;
          margin-left: 40px;
          position: relative;
          background: url(../../assets/icons.d354c61.png) no-repeat 0 -292px;
          .number {
            height: 20px;
            line-height: 20px;
            margin-top: 12px;
            color: #999;
            font-family: math;
          }
          .text {
            height: 24px;
            line-height: 24px;
            font-size: 14px;
            color: #999;
          }
        }
        .item:first-child {
          background: none;
        }
        .active {
          .number {
            color: #000;
          }
          .text {
            color: #000;
          }
        }
      }
    }
    .payment-con {
      font-size: 12px;
      .pay-box {
        background: #f9f9f9;
        padding: 20px;
        .pay-info {
          padding-left: 52px;
          position: relative;
          .tag {
            width: 32px;
            height: 32px;
            position: absolute;
            left: 0;
            top: 5px;
          }
          .success {
            background: url(../../assets/icons.d354c61.png) no-repeat 0 -476px;
          }
          .item {
            display: flex;
            justify-content: space-between;
            .tit {
              font-size: 14px;
              height: 20px;
              line-height: 20px;
              flex: 1;
              font-weight: 600;
            }
            .total-pay {
              height: 20px;
              line-height: 20px;
              .price {
                font-size: 18px;
                display: inline-block;
                vertical-align: top;
                line-height: 20px;
                margin-right: 3px;
                font-family: arial;
                color: #e1251b;
              }
            }
            .time {
              height: 12px;
              line-height: 12px;
              margin-top: 10px;
              flex: 1;
              color: #999;
              display: flex;
              .warning {
                color: #e1251b;
              }
            }
            .reset-time {
              height: 12px;
              line-height: 12px;
              margin-top: 10px;
              flex: 1;
              color: #999;
              display: flex;
            }
          }
        }
      }
      .section-payment {
        margin-top: 30px;
        .tit {
          margin-bottom: 20px;
          font-size: 14px;
          padding: 0 20px;
          font-weight: 600;
          color: #000;
        }
        .con {
          display: flex;
          .item {
            width: 174px;
            height: 60px;
            line-height: 60px;
            margin-left: 20px;
            margin-bottom: 20px;
            border: 1px solid #e0e0e0;
            text-align: center;
            cursor: pointer;
            overflow: hidden;
            transition: all 0.2s;
            border-color: #e1251b;
            img {
              width: 100%;
              height: 100%;
            }
          }
        }
        .btn {
          margin-top: 10px;
          margin-left: 20px;
          display: block;
          font-size: 15px;
          font-weight: 600;
          width: 174px;
          height: 42px;
          line-height: 42px;
          background: #e1251b;
          text-align: center;
          color: #fff;
          border-radius: 2px;
          text-decoration: none;
        }
      }
    }
  }
}
</style>
